package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.entity.Knowleage;
import com.hbnu.system.service.IKnowleageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/knowleage")
@Api(tags = "申报材料模块")
public class KnowleageController {
    @Autowired
    IKnowleageService iKnowleageService;

    @ApiOperation("申报材料-录入")
    @PostMapping("/addAppliMaterials")
    public Rest<Boolean> addAppliMaterials(@RequestBody Knowleage knowleage){
        boolean add = iKnowleageService.addAppliMaterials(knowleage);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("申报材料-删除")
    @GetMapping("/DeleteAppliMaterials")
    public Rest<Boolean> DeleteAppliMaterials(String AppliMaterialsID){
        boolean delete = iKnowleageService.deleteAppliMaterials(AppliMaterialsID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("申报材料-修改")
    @PostMapping("/updateAppliMaterials")
    public Rest<Boolean> updateAppliMaterials(@RequestBody Knowleage knowleage){
        boolean update = iKnowleageService.updateAppliMaterials(knowleage);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键申报材料查询")
    @GetMapping("/GetAppliMaterialsById")
    public Rest<Knowleage> GetAppliMaterialsById(String AppliMaterialsID){
        Knowleage knowleage = iKnowleageService.getAppliMaterials(AppliMaterialsID);
        return Rest.success(knowleage);
    }

    @ApiOperation("申报材料-分页查询")
    @PostMapping ("/pageAppliMaterialsCondition")
    public Rest<CommonPage<Knowleage>> pageAppliMaterialsCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Knowleage> page = iKnowleageService.pageCondition(searchTaskDTO);
        CommonPage<Knowleage> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }

}

